package cn.edu.nju.software.lilybbs.progdlg;


import cn.edu.nju.software.lilybbs.R;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

public class WaitingDialog extends Dialog{

	private TextView tv;
	private ImageView iv;
	
	
	public WaitingDialog(Context context, int theme) {
		super(context, theme);
		// TODO Auto-generated constructor stub
	}

	protected WaitingDialog(Context context, boolean cancelable,
			OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
		// TODO Auto-generated constructor stub
	}

	public WaitingDialog(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		View view = LayoutInflater.from(getContext()).inflate(R.layout.waiting, null);
		tv = (TextView) view.findViewById(R.id.waiting_tv);
		iv = (ImageView) view.findViewById(R.id.waiting_iv);		
		iv.setImageResource(R.drawable.circular);
		setContentView(view);
	}
	
	@Override
	public void show() {
		super.show();
		Animation a = AnimationUtils.loadAnimation(getContext(), R.drawable.custom_progress_draw);
		LinearInterpolator lir = new LinearInterpolator();    
		a.setInterpolator(lir);
		iv.startAnimation(a);
	}
	
	@Override
	public void dismiss() {
		// TODO Auto-generated method stub
		super.dismiss();
		iv.clearAnimation();
	}
	
	public void setMsg(String txt) {
		tv.setText(txt);
	}
	
}